
#pragma once

#include "hge.h"
#include "hgegui.h"
#include "hgefont.h"

class View;
class TitleView;

class Application
{
public:

	// Static get/create function
	static Application *GetApp();

	// Starts running the application
	void Exec();

	// Fonts
	hgeFont *GetSmallFont() const { return smallFont; }
	hgeFont *GetLargeFont() const { return largeFont; }

	// Cursor
	hgeSprite *GetCursorSprite() const { return cursor; }
	void RenderCursorSprite() const;

	// Main TitleView
	TitleView *GetTitleView() const { return title; }

	// Screen variables
	float ScreenWidth() const { return screenWidth; }
	float ScreenHeight() const { return screenHeight; }
	bool  FullScreen()  const { return fullScreen; }

private:

	// Constructor
	Application();

	// Reads in the config file
	bool ReadConfigFile();

	// Loads in HGE
	void LoadHGE();
	// Creates and sets up the window
	void CreateHGEWindow();
	// Loads in texture and effect data
	bool LoadData();
	// Loads in the unit data
	void LoadUnits();

	// Renders and processes
	bool RenderFrame();
	bool ProcessFrame();

	// Screen variables
	float screenWidth, screenHeight;
	bool fullScreen;

	// Current view
	bool enteringNewView;
	View *view;
	TitleView *title;

	// Cursor
	HTEXTURE cursorTex;
	hgeSprite *cursor;

	// Fonts
	hgeFont *smallFont;
	hgeFont *largeFont;

	// Global application
	static Application *mainApp;

	// Global function to pass to HGE
	static bool _RenderFrame()  { return GetApp()->RenderFrame(); }
	static bool _ProcessFrame() { return GetApp()->ProcessFrame(); }
};

// Inline call to Application public functions
inline hgeFont *GetSmallFont() { return Application::GetApp()->GetSmallFont(); }
inline hgeFont *GetLargeFont() { return Application::GetApp()->GetLargeFont(); }
inline hgeSprite *GetCursorSprite() { return Application::GetApp()->GetCursorSprite(); }
inline void RenderCursorSprite() { Application::GetApp()->RenderCursorSprite(); }
inline TitleView *GetTitleView() { return Application::GetApp()->GetTitleView(); }

inline float ScreenWidth() { return Application::GetApp()->ScreenWidth(); }
inline float ScreenHeight() { return Application::GetApp()->ScreenHeight(); }
inline bool  FullScreen()  { return Application::GetApp()->FullScreen(); }
